<?php
if ( !defined( "IN_OP" ) )
{
    exit( "You can't access this file directly..." );
}
require_once( "class_3d/CheckMode_3d.php" );
$gametype = intval( getvar( "gametype" ) );
$chk = new CheckMode_3d( $curruser['acl'], 3, $gametype );
$chk->checkShow3dPage();
$betname_3d = judge_type( $gametype );
$show5N = getShow35( $gametype );
unset( $chk );
$tblName = $g_gametype_3d[$gametype]['ch'];
$tbl = $g_gametype_3d[$gametype]['en'];
$ui = new UI_3D( true );
$tpl = new Template2();
$conf = new Config();
include_once( "class_3d/AutoRateConfig_3d.php" );
$AutoRateConfig_3d = new AutoRateConfig_3d( $betname_3d, $g_autorate_3d, $gametype );
if ( $show5N )
{
    $startI = 2;
    $sub0Title = "後三";
}
else
{
    $startI = 0;
    $sub0Title = "";
}
if ( ispost( ) )
{
    $longautoadown = intval( getvar( "longautoadown_{$tbl}" ) );
    $conf->set( "longautoadown_{$tbl}", $longautoadown );
    $fields_data = array();
    foreach ( $betname_3d as $keyStr => $val )
    {
        $keyArr = explode( "_", $keyStr );
        $key = $keyArr[0];
        $subid = $keyArr[1];
        if ( in_array( $key, $g_autorate_3d ) )
        {
            $money = "money".$keyStr;
            $downrate = "downrate".$keyStr;
            $uprate = "uprate".$keyStr;
            $limitrate = "limitrate".$keyStr;
            $typeflag = "typeflag".$keyStr;
            $uprateData = "";
            $amount_255 = "amount_255".$keyStr;
            if ( !isset( $_POST[$amount_255] ) )
            {
                continue;
            }
            if ( isset( $_POST[$uprate] ) )
            {
                $uprateData = floatval( trim( $_POST[$uprate] ) );
            }
            else
            {
                $uprateData = 0;
            }
            $amount_255_val = intval( trim( $_POST[$amount_255] ) );
            if ( $amount_255_val < 0 )
            {
                $amount_255_val = 0;
            }
            $moneyTemp = intval( trim( $_POST[$money] ) );
            $typeflagTemp = intval( trim( $_POST[$typeflag] ) );
            $fields_data[] = array( "id" => $key, "subid" => $subid, "money" => $moneyTemp, "downrate" => floatval( trim( $_POST[$downrate] ) ), "uprate" => $uprateData, "limitrate" => floatval( trim( $_POST[$limitrate] ) ), "typeflag" => $typeflagTemp, "amount_255" => $amount_255_val );
            if ( $moneyTemp == 0 )
            {
                getdb( "update autorate_config_ss set money = 0, updatetime = '".date( "Y-m-d H:i:s" )."' where bettype = {$key} and  subid = {$subid} and typeflag = {$typeflagTemp} and money != 0" );
            }
        }
    }
    $numsArr = array();
    $subid = $startI;
    while ( 0 - 1 < $subid )
    {
        if ( isset( $_POST["bettype_200_{$subid}"] ) )
        {
            $err = false;
            $numsArr = explode( ",", $_POST["bettype_200_{$subid}"] );
            if ( $numsArr[0] == "" )
            {
                $err = true;
                $conf->set( "3CharSpecNumbers_{$tbl}_{$subid}", "" );
            }
            else
            {
                $i = 0;
                while ( $i < count( $numsArr ) )
                {
                    if ( strlen( trim( strval( $numsArr[$i] ) ) ) != 3 )
                    {
                        $err = true;
                        break;
                    }
                    ++$i;
                }
            }
            if ( !$err )
            {
                $conf->set( "3CharSpecNumbers_{$tbl}_{$subid}", implode( ",", $numsArr ) );
                $key = "200_".$subid;
                $money = "money".$key;
                $downrate = "downrate".$key;
                $uprate = "uprate".$key;
                $limitrate = "limitrate".$key;
                $typeflag = "typeflag".$key;
                $uprateData = "";
                $amount_255 = "amount_255".$key;
                if ( isset( $_POST[$uprate] ) )
                {
                    $uprateData = floatval( trim( $_POST[$uprate] ) );
                }
                else
                {
                    $uprateData = 0;
                }
                $amount_255_val = intval( trim( $_POST[$amount_255] ) );
                if ( $amount_255_val < 0 )
                {
                    $amount_255_val = 0;
                }
                $moneyTemp = intval( trim( $_POST[$money] ) );
                $typeflagTemp = intval( trim( $_POST[$typeflag] ) );
                $fields_data[] = array( "id" => "200", "subid" => $subid, "money" => $moneyTemp, "downrate" => floatval( trim( $_POST[$downrate] ) ), "uprate" => $uprateData, "limitrate" => floatval( trim( $_POST[$limitrate] ) ), "typeflag" => $typeflagTemp, "amount_255" => $amount_255_val );
            }
        }
        --$subid;
    }
    if ( 0 < count( $fields_data ) )
    {
        $AutoRateConfig_3d->updateAutoRate( $fields_data );
    }
    unset( $fields_data );
}
$longautoadownVal = intval( $conf->get( "longautoadown_{$tbl}" ) );
$theadContent = "<tr class=\"bgClc_".$gametype."\"><td>玩法</td><td>金额</td><td>降赔率</td><td>升赔率</td><td>最低赔率</td><td>实货限额</td></tr>";
$autorateData = $AutoRateConfig_3d->getAutoRateAll();
$tempStr = "";
$tempI = 0;
$tempClass = 2;
$showHeadArr = array( "13_2" => "13_2", "20_2" => "20_2", "24_2" => "24_2", "48_0" => "48_0" );
if ( $autorateData == false )
{
    $tempStr = "<tr class=\"td2\"><td colspan=6 align=ccenter>查无相关资料</td></tr>";
}
else
{
    foreach ( $betname_3d as $keyStr => $valName )
    {
        $keyArr = explode( "_", $keyStr );
        $key = $keyArr[0];
        $subid = $keyArr[1];
        if ( isset( $showHeadArr[$keyStr] ) )
        {
            $tempStr .= $theadContent;
        }
        if ( isset( $autorateData[$keyStr] ) )
        {
            $val = $autorateData[$keyStr];
            ++$tempI;
            $tempClass = $tempClass % 2 + 1;
            $tempStr .= "<tr class=\"td2 row{$tempClass}\">";
            $tempStr .= "<td class=\"td17\" align=left>{$valName}<input type=\"hidden\" value=\"".$val['typeflag']."\" name=\"typeflag".$keyStr."\"  /></td>";
            $tempStr .= "<td><input type=\"text\" name=\"money".$keyStr."\" value=\"".$val['money']."\" size=\"8\" /></td>";
            $tempStr .= "<td><input type=\"text\" name=\"downrate".$keyStr."\" value=\"".$val['downrate']."\" size=\"5\" /></td>";
            $tempStr .= "<td>";
            if ( $val['typeflag'] == 1 )
            {
                $tempStr .= "<input type=\"text\" name=\"uprate".$keyStr."\" value=\"".$val['uprate']."\" size=\"5\" />";
            }
            else
            {
                $tempStr .= "&nbsp;";
            }
            $tempStr .= "</td>";
            $tempStr .= "<td><input type=\"text\" name=\"limitrate".$keyStr."\" value=\"".$val['limitrate']."\" size=\"5\" /></td>";
            $tempStr .= "<td><input type=\"text\" name=\"amount_255".$keyStr."\" value=\"".$val['amount_255']."\" size=\"5\" /></td>";
            $tempStr .= "</tr>";
        }
        else
        {
            $tempStr .= "<tr class=\"td2 row{$tempClass}\"><th>{$valName}</th><td colspan=5 align=ccenter>查无此玩法的相关资料，请洽系统管理者</td></tr>";
        }
    }
    /*$subidArr = array( 0 => $sub0Title, 1 => "中三", 2 => "前三" );
    $subid = $startI;
    while ( 0 - 1 < $subid )
    {
        $keyStr = "200_".$subid;
        if ( isset( $autorateData[$keyStr] ) )
        {
            $nums = $conf->get( "3CharSpecNumbers_{$tbl}_{$subid}" );
            $tempStr .= "<tr class=\"bgClc_".$gametype."\"><td>".$subidArr[$subid]."三字组合特别号</td><td>金额</td><td>降赔率</td><td>升赔率</td><td>最低赔率</td><td>实货限额</td></tr>";
            $val = $autorateData[$keyStr];
            ++$tempI;
            $tempClass = $tempClass % 2 + 1;
            $tempStr .= "<tr class=\"td2 row{$tempClass}\">";
            $tempStr .= "<td><input type=\"text\" name=\"bettype_200_{$subid}\" value=\"".$nums."\" size=\"20\" /></td><input type=\"hidden\" value=\"".$val['typeflag']."\" name=\"typeflag".$keyStr."\"  /></td>";
            $tempStr .= "<td><input type=\"text\" name=\"money".$keyStr."\" value=\"".$val['money']."\" size=\"8\" /></td>";
            $tempStr .= "<td><input type=\"text\" name=\"downrate".$keyStr."\" value=\"".$val['downrate']."\" size=\"5\" /></td>";
            $tempStr .= "<td>";
            if ( $val['typeflag'] == 1 )
            {
                $tempStr .= "<input type=\"text\" name=\"uprate".$keyStr."\" value=\"".$val['uprate']."\" size=\"5\" />";
            }
            else
            {
                $tempStr .= "&nbsp;";
            }
            $tempStr .= "</td>";
            $tempStr .= "<td><input type=\"text\" name=\"limitrate".$keyStr."\" value=\"".$val['limitrate']."\" size=\"5\" /></td>";
            $tempStr .= "<td><input type=\"text\" name=\"amount_255".$keyStr."\" value=\"".$val['amount_255']."\" size=\"5\" /></td>";
            $tempStr .= "</tr>";
        }
        else
        {
            getdb( "INSERT INTO `autorate_config_{$tbl}` (`bettype_id`,subid ,`money` ,`downrate` ,`uprate` ,`limitrate` ,`typeflag` ,`betname` ,`amount_255` ) VALUES ('200','{$subid}' ,'0', '0', '0.00', '0.00', '0', '', '0')" );
        }
        --$subid;
    }*/
    unset( $autorateData );
}
if ( 2 < $gametype )
{
    $theadContent = "<tr class=\"msgBox-yellow\"><td colspan=\"6\" style=\"text-align:left\"><font style=\"font-size:13px;font-weight:900;\">二面长龙<input type=\"input\" size=\"1\" value=\"".$longautoadownVal."\" name=\"longautoadown_".$tbl."\" />期不出，自动累进降倍(0期不降倍)<input type=\"submit\" value=\"更改\"></font>"."<a class=\"tooltipsSite\" href=\"#tooltipsSite\">(说明)<SPAN><DIV> 1) 设定与自动赔率共用。<br /> 2) 金额设0时不降倍。<br /> 3) 降倍采累进降倍方式。例：设「10」期，当连10期不出时，降1码；连11期不出时，降2码...以此类推 4) 本设定不含龙虎和。<br /></DIV></SPAN></a></td></tr>".$theadContent;
}
$tpl->load( "main", "autorate_3d.htm" );
$tpl->set( array( "action" => "op.php?op=admin&fp=autorate_3d&gametype={$gametype}", "reload" => "op.php?op=admin&fp=autorate_3d&gametype={$gametype}", "tbodycontente" => $tempStr, "tblName" => $tblName, "theadContent" => $theadContent, "gametype" => $gametype ) );
$ui->set( "csslink", "<link REL=\"StyleSheet\" type=\"text/css\" href=\"core/tpl/k2/rate3d.css\">" );
$ui->header();
include( "admin_menu_3d.php" );
$tpl->show( "main" );
echo "</td></tr></table>";
$ui->footer();
?>